﻿<%@ Control Language="VB" ClassName="alphalinksvb" %>

<script runat="server">
    Private letters As String() = {"All", "A", "B", "C", "D", "E", _
     "F", "G", "H", "I", "J", "K", _
     "L", "M", "N", "O", "P", "Q", _
     "R", "S", "T", "U", "V", "W", _
     "X", "Y", "Z"}

    Private selectedLetter As String
    Private selectedIndex As Integer

    Private Sub Page_Load()
        If ViewState("selectedLetter") Is Nothing Then
            selectedLetter = "All"
            ViewState("selectedLetter") = "All"
        End If
    End Sub

    Public Sub Page_PreRender()
        '
        '		 * I moved this out of the Page_Load so that I could disable the selected link.
        '		 * Prior to moving it out of Page_Load, the deselected link lagged one behind, because
        '		 * Page_Load fires prior to the command event handler.
        '		 

        __theAlphalink.DataSource = letters
        __theAlphalink.DataBind()
    End Sub

    Public Property Letter() As String
        Get
            Return ViewState("selectedLetter").ToString()
        End Get
        Set(value As String)
            ViewState("selectedLetter") = value
        End Set
    End Property

    Private Sub [Select](sender As Object, e As CommandEventArgs)
        selectedLetter = e.CommandArgument.ToString()
        ViewState("selectedLetter") = e.CommandArgument.ToString()
    End Sub

    Private Sub DisableSelectedLink(sender As Object, e As RepeaterItemEventArgs)
        Dim lb As LinkButton = DirectCast(e.Item.Controls(1), LinkButton)
        If lb.Text = Letter Then
            lb.Enabled = False
        End If
    End Sub
    </script>
<asp:Repeater runat="server" ID="__theAlphalink" OnItemDataBound="DisableSelectedLink">
<ItemTemplate>
	<asp:LinkButton runat="server" ID="link" 
		text="<%# Container.DataItem %>"
		CommandName="Filter"
		CommandArgument='<%# DataBinder.Eval(Container, "DataItem")%>'
		OnCommand="Select"
		 />&nbsp;
</ItemTemplate>
</asp:Repeater>
